package pers.sloera.leetcode;

import java.util.Scanner;

/**
 * class pers.sloera.leetcode
 * user sloera
 * date 6/30/21
 */
public class packageSolution {
    public static void main(String[] args) {
        int dp[][] = new int[35][205];
        int w[] = new int[35];
        int v[] = new int[35];
        int c, n;
        Scanner scanner = new Scanner(System.in);
        c = scanner.nextInt();
        n = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            w[i] = scanner.nextInt();
            v[i] = scanner.nextInt();
        }
        System.out.println(c);
        System.out.println(n);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= c; j++) {
                if (j < w[i]) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(dp[i][j]);
                System.out.print("\t");
            }
            System.out.println();
        }

    }
}
